<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>监听表单的提交事件</title>
</head>
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.0/css/bootstrap.css" rel="stylesheet">
<body>
  
  <form action="/login" id="f1">
    <input type="text" name="user_name" id="">
    <input type="password" name="password" id="">
    <button type="submit">提交</button>
  </form>

</body>
<script type="text/javascript" src="./jquery-3.6.0/jQuery3.6.js"></script>
<script type="text/javascript">
  $(function(){
    // 第一种方式
    // $("#f1").submit(()=>{
    //   console.log("监听到了");
    // })

    //第二种方式
    $("#f1").on("submit", function(e){
      e.preventDefault();
      // alert("监听到了2");

      var data = $(this).serialize();
      console.log(data);

    })
  })
</script>
</html>